<template>
	<view>
		<view class="box">
			<view class="box-title e-m-b-20 c-35">
				{{ $t(`user.${type}额度`) }}
			</view>
			<view class="e-p-t-42 e-p-b-34">
				<e-input v-if="!account || !account.hasFixedConvert || !account.fixedConvertMoney" v-model="money" border="none" :placeholder="$t(`user.请输入${type}额度`)"></e-input>
				<text v-else>{{account.fixedConvertMoney}}</text>
			</view>
			<view class="e-font-26 e-p-t-20 e-p-b-20 e-flex e-flex-between">
				<text class="c-be">{{ $t(`user.可${type}额度`) }} {{ max }}</text>
				<text class="c-primary" @tap="handleAll">{{$t('common.全部')}}</text>
			</view>
			<view class="e-flex e-flex-between c-35">
				<text class="box-title ">
					{{ $t('user.到账额度') }}
				</text>
				<text class="fw-600 e-font-48">{{arrival}}</text>
			</view>
			<view class="e-m-t-20 c-be" v-if="account && account.hasScScale">
				<view class="e-m-b-10">
					{{getScScale}}
				</view>
				<view class="">
					价格：{{account.params.matchPrice}}
				</view>
			</view>
			<view class="e-m-t-20 c-be" v-else>
				{{$t(`user.${type}比例`)}} = 1 : {{operationa}}
			</view>
		</view>
		<view class="e-p-t-20  e-flex e-rela"  @tap.stop="showAgreementPop = true">
			<radio style="transform:scale(0.8)" :checked="isAgree" :color="AppSkin.primary"  />
			<view class="e-abso" style="width: 100rpx;height: 40rpx;z-index: 999;">
				
			</view>
			<text class="keep-all">{{ $t('public.我已阅读并同意') }}</text>
			<text v-if="ttype === 1">《转账协议》</text>
			<text v-if="ttype === 2">《转换协议》</text>
		</view>
		<view class="e-m-t-60">
			<e-button size="large"  :color="color" shape="circle" :text="$t(`user.立即${type}`)" @click="transfer" :throttleTime="1000"></e-button>
		</view>
		<agreement-pop :showPop="showAgreementPop" @agree="isAgree = true" @cancel="isAgree = false" :isAgree="isAgree"
			 @close="showAgreementPop = false" :agreeId="ttype === 1 ? 20 : 21"></agreement-pop>
	</view>
</template>

<script>
export default {
	// #ifdef MP-WEIXIN
	// 将自定义节点设置成虚拟的，更加接近Vue组件的表现
	options: {
		virtualHost: true
	},
	// #endif
	props: {
		max: Number,
		scale:Number,
		operationa:Number,
		scaleType:Number,
		type:String,
		color:String,
		amortizedRule:Array,
		ttype:Number,
		account:Object
	},
	data () {
		return {
			money:null,
			isAgree:false,
			showAgreementPop:false
		}
	},
	computed:{
		getScScale() {
			if (this.account.scConvertType === 1) {
				return `比例：1:${this.account.params.matchPrice}`
			} else {
				return `比例：${this.account.params.matchPrice}:1`
			}
		},
		arrival () {
			if (this.account && this.account.hasScScale) {
				if (this.account.scConvertType === 1) {
					return this.$accMul(this.money||0,this.account.params.matchPrice)
				} else {
					return this.$accDiv(this.money||0,this.account.params.matchPrice)
				}
			} else {
				if (this.account && this.account.hasFixedConvert && this.account.fixedConvertMoney) {
					this.money =  this.account.fixedConvertMoney
				}
				let number = this.$accMul(this.money||0,this.operationa)
				if(this.scaleType === 1){
					let scale = this.$accMul(number,this.$accDiv(this.scale,100))
					number = this.$accAdd(number,-scale).toFixed(2)
				}else{
					number = this.$accAdd(number,-this.scale).toFixed(2)
				}
				return number > 0 ? number : 0
			}
		}
	},
	methods:{
		handleAll() {
			if (this.account.hasFixedConvert && this.account.fixedConvertMoney) {
				this.money = this.account.fixedConvertMoney
			} else {
				this.money = this.max
			}
		},
		transfer () {
			if (!this.isAgree) {
				const title = this.ttype === 1 ? '请先阅读并同意转账协议' : '请先阅读并同意转换协议'
				return this.$toastApp(title)
			}
			if (this.account && this.account.hasFixedConvert && this.account.fixedConvertMoney) this.money =  this.account.fixedConvertMoney
			this.$emit('transfer',this.money)
		},
	}
}
</script>

<style lang="scss" scoped>
.c-be {
	color: #bebebe;
}
.box {
	height: 550rpx;
	background: #feffff;
	box-shadow: 0 4rpx 20rpx 0 #f3f3f3;
	border-radius: 10rpx;
	padding: 60rpx 30rpx;
	.box-title {
		line-height: 42rpx;
		font-size: 30rpx;
	}
}
</style>
